﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.IO;
using System.Runtime.Remoting.Metadata.W3cXsd2001;

namespace Mesne
{
    public class Serial : SerialPort
    {
        private static Serial serial;
        private static object portLock = new object();

        private Serial()
        {
            PortName = "COM1";
            BaudRate = 19200;
            Parity = System.IO.Ports.Parity.None;
            DataBits = 8;
            StopBits = System.IO.Ports.StopBits.One;
            Encoding = ASCIIEncoding.ASCII;
            if (IsOpen)
            {
                Close();
            }
            Open();
        }

        public static SerialPort Port
        {
            get
            {
                lock (portLock)
                {
                    if (serial == null)
                    {
                        serial = new Serial();
                    }
                    return serial;
                }
            }
        }

        ~Serial()
        {
            if (IsOpen)
            {
                Close();
            }
        }
    }
}
